<?php 
class Member_model extends Model {
	
	var $tbl_name = 'member';
	var $tbl_par  = 'member_par';
	var $tbl_pro  = 'member_pro';
	
	function Member_model() {
		parent::Model();
	}
	
	function addMember($ary_info=array()) {
		$this->db->insert($this->tbl_name, $ary_info);
		
		return $this->db->insert_id();
	} 
	
	function updateMember($id=0,$ary_info) {
		$this->db->where(array('id'=>$id));
		$this->db->update($this->tbl_name, $ary_info);
	}  
	
	function addMember_par($ary_info=array()) {
		$this->db->insert($this->tbl_par, $ary_info);
		return $this->db->insert_id();
	}
	
	function updateMember_par($id=0,$ary_info) {
		$this->db->where(array('member_id'=>$id));
		$this->db->update($this->tbl_par, $ary_info);
	}  
	
	function addMember_pro($ary_info=array()) {
		$this->db->insert($this->tbl_pro, $ary_info);
		return $this->db->insert_id();
	}
	
	function updateMember_pro($id=0,$ary_info) {
		$this->db->where(array('member_id'=>$id));
		$this->db->update($this->tbl_pro, $ary_info);
	}  
	
	function getMember($ary_info) {
		$this->db->where($ary_info);
		
		$query = $this->db->get($this->tbl_name);
		if ($query->num_rows()>0) {
			return $query->row_array(); 
		}
	}
	
	function getMember_par($ary_info) {
		$this->db->select('mem.*, par.firstname,
			par.lastname, par.birthday, par.gender, par.display_image, par.address, par.country_id,
			par.city_id, par.district_id, par.phone
		');
		$this->db->where($ary_info);
		$this->db->join($this->tbl_par.' as par ','mem.id = par.member_id','inner');
		
		$query = $this->db->get($this->tbl_name.' as mem ');
		if ($query->num_rows()>0) {
			return $query->row_array(); 
		}
	}
	
	function getMember_pro($ary_info) {
		$this->db->select('mem.*,
			pro.company_name, pro.address, pro.country_id, pro.city_id, pro.district_id, pro.display_image,
			pro.phone, pro.intro_content, pro.website
		');
		$this->db->where($ary_info);
		$this->db->join($this->tbl_pro.' as pro ','mem.id = pro.member_id','inner');
		
		$query = $this->db->get($this->tbl_name.' as mem ');
		if ($query->num_rows()>0) {
			return $query->row_array(); 
		}
	}
}